package org.emergency.framework.action.oa;

import java.util.List;

import javax.annotation.Resource;

import org.emergency.framework.action.BaseAction;
import org.emergency.framework.model.TbRole;
import org.emergency.framework.service.oa.ITbRoleService;
import org.springframework.stereotype.Repository;

@Repository("tbRoleAction")
public class TbRoleAction extends BaseAction{

	@Resource(name = "roleServiceImpl")
	ITbRoleService service;

	String message;

	List<TbRole> tbRoles;
	
	TbRole tbRole;

	/**
	 * 查询所有
	 * @return
	 */
	public String queryAllRoles() {
		this.setMessage("查询成功");	
		try {
			tbRoles = service.findAll();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			this.setMessage("查询失败");
		}
		return "queryAllRoles";
	}
	
	
	public String addRold(){
		this.setMessage("增加成功");	
		try {
			service.save(tbRole);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			this.setMessage("增加失败");	
		}
		return "addRole";
	}
	
	
	/**
	 * 通过id删除角色
	 * @return
	 */
	public String deleteRoleById(){
		this.setMessage("删除成功");
		try {
			service.delete(tbRole);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			this.setMessage("删除失败");
			e.printStackTrace();
		}
		
		return "deleteRoleById";
	}

	public ITbRoleService getService() {
		return service;
	}

	public void setService(ITbRoleService service) {
		this.service = service;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public List<TbRole> getTbRoles() {
		return tbRoles;
	}

	public void setTbRoles(List<TbRole> tbRoles) {
		this.tbRoles = tbRoles;
	}


	public TbRole getTbRole() {
		return tbRole;
	}


	public void setTbRole(TbRole tbRole) {
		this.tbRole = tbRole;
	}
	
	

}
